package com.itheima.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.pojo.Book;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class BookServiceImplTestCase {
    @Autowired
    private BookService bookService;

    @Test
    void testGetById(){
        System.out.println(bookService.getById(1));
    }

    //添加数据
    @Test
    public void testSave(){
        Book book = new Book();
        book.setType("恐吓");
        book.setName("夺魂");
        book.setDescription("很吓人");
        bookService.save(book);
    }
    //修改数据
    @Test
    public void testUpdate(){
        Book book = new Book();
        book.setId(10);
        book.setType("恐吓");
        book.setName("夺魂2");
        book.setDescription("一点不吓人");
        bookService.update(book);
    }
    //删除数据
    @Test
    public void testDelete(){
        bookService.delete(13);

    }
    //查询全部
    @Test
    public void testGetAll(){

        System.out.println(bookService.getAll());

    }
    //分页查询
    @Test
    public void testGetPage(){
        IPage<Book> page = bookService.getPage(1, 5);
        //数据list集合
        System.out.println(page.getRecords());
        //能有几页
        System.out.println(page.getPages());//2
        //当前页
        System.out.println(page.getCurrent());//1
        //每页显示的条数
        System.out.println(page.getSize());//5
        //总条数
        System.out.println(page.getTotal());//10
    }


}
